package it.amicosmanettone.whatsimage;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.graphics.Typeface;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

public class WelcomeActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_welcome);
		
		final Bundle extras = getIntent().getExtras();

		String messageBody = extras.getString("messageBody");
		final Boolean warning = extras.getBoolean("warning");
		
		TextView welcome = (TextView)findViewById(R.id.welcome_text_welcome);
		TextView body = (TextView)findViewById(R.id.welcome_text_body);
		
		Typeface daddy = Typeface.createFromAsset(getAssets(), "daddy.ttf");
		Typeface moon = Typeface.createFromAsset(getAssets(), "moon.ttf");
		
		body.setText(messageBody);
		
		welcome.setTypeface(daddy);
		welcome.refreshDrawableState();
		body.setTypeface(moon);
		body.refreshDrawableState();
		
		final SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
		
		final Editor EDIT = sharedPref.edit();
		
		Button button_close = (Button)findViewById(R.id.welcome_button_close);
		Button button_login = (Button)findViewById(R.id.welcome_button_login);
		
		final Intent warningActivity = new Intent(this, WarningActivity.class);
		final Intent loginActivity = new Intent(this, LoginActivity.class);
		
		final Intent main = new Intent(this, MainActivity.class);
		
		button_close.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
            	
            	if(warning){
        			
        			EDIT.putBoolean("show_welcome_message", false).commit();
        			
        			String warningText = extras.getString("warningText");
        			warningActivity.putExtra("warningText", warningText);
        			warningActivity.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK );
            		startActivity(warningActivity);
            		overridePendingTransition(R.xml.translate_in, R.xml.translate_out);
            		finish();
        			
        		}else{
            	
        			EDIT.putBoolean("show_welcome_message", false).commit();
            	
        			main.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK );
        			startActivity(main);
        			overridePendingTransition(R.xml.translate_in, R.xml.translate_out);
        			finish();
        		
        		}
        		
            }
        });
		
		button_login.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
            	
            	Toast.makeText(getApplicationContext(), getText(R.string.toast_function_not_available).toString(), Toast.LENGTH_SHORT).show();
            	
            	/*if(warning){
        			
            		EDIT.putBoolean("show_welcome_message", false).commit();
                	String warningText = extras.getString("warningText");
                	loginActivity.putExtra("warningText", warningText);
                	loginActivity.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK );
                	startActivity(loginActivity);
                	overridePendingTransition(R.xml.translate_in, R.xml.translate_out);
                	finish();
        			
        		}else{
            	
        			EDIT.putBoolean("show_welcome_message", false).commit();
                	loginActivity.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK );
                	startActivity(loginActivity);
                	overridePendingTransition(R.xml.translate_in, R.xml.translate_out);
                	finish();
        		
        		}*/
        		
            }
        });
		
	}
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		
		return true;
	}
	
	@Override
    public boolean onOptionsItemSelected(MenuItem item) {
            switch (item.getItemId()) {
            
            case android.R.id.home:
                
            	Log.e("WELCOME_ACTIVITY", "PREMO BACK");
            	
                return true;
                
            }
            
            return super.onOptionsItemSelected(item);
    }

}
